package com.px.controller;

import com.px.mapper.ShCommentMapper;
import com.px.pojo.ShComment;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class ProviderShCommentController {

    @Resource
    private ShCommentMapper shCommentMapper;

    @PostMapping("/api/provider/selectShCommentList")
    public List<ShComment> selectShCommentList(@RequestParam Integer commentType,
                                                   @RequestParam Integer commodityId,
                                                   @RequestParam Integer userId,
                                                   @RequestParam Integer pageBegin,
                                                   @RequestParam Integer pageSize)throws Exception{
        List<ShComment> shComments = shCommentMapper.selectShCommentList(commentType, commodityId, userId, pageBegin, pageSize);
        if("".equals(shComments) && null == shComments){
            return null;
        }
        return shComments;
    }

    @PostMapping("/api/provider/selectShCommentCount")
    public Integer selectShCommentCount(@RequestParam Integer commentType,
                                        @RequestParam Integer commodityId,
                                        @RequestParam Integer userId)throws Exception{
        int count = shCommentMapper.selectShCommentCount(commentType, commodityId,userId);
        if (count > 0) {
            return count;
        }
        return 0;
    }

    @PostMapping("/api/provider/selectShComment")
    public ShComment selectShComment(@RequestParam Integer commentId)throws Exception{
        ShComment shComment = shCommentMapper.selectShComment(commentId);
        if("".equals(shComment) && null == shComment){
            return null;
        }
        return shComment;
    }

    @PostMapping("/api/provider/insertShComment")
    public Integer insertShComment(@RequestBody ShComment shComment)throws Exception{
        int insert = shCommentMapper.insertShComment(shComment);
        if (insert > 0) {
            return insert;
        }
        return 0;
    }

    @PostMapping("/api/provider/updateShComment")
    public Integer updateShComment(@RequestBody ShComment shComment)throws Exception{
        int update = shCommentMapper.updateShComment(shComment);
        if (update > 0) {
            return update;
        }
        return 0;
    }

    @PostMapping("/api/provider/deleteShComment")
    public Integer deleteShComment(@RequestParam Integer id)throws Exception{
        int delete = shCommentMapper.deleteShComment(id);
        if (delete > 0) {
            return delete;
        }
        return 0;
    }
}
